package com.koc.robot;

import android.opengl.GLES11;

import com.koc.robot.common.Vector;

public class Coin {
	private Scene mScene;
	
	private Texture mTexture;
	private Quad mQuad;
	private BlockPoint mPosition;
	
	private boolean mHasCollected;
	
	private final float COIN_SIZE = 20;
	
	public Coin(Scene scene)
	{
		mScene = scene;
		mHasCollected = false;
				
		init();
	}
	
	public void init()
	{
		mTexture = new Texture(Global.context);
		//mTexture.load(R.drawable.robot);
		mTexture.load("coin.png");
		mQuad = new Quad(mTexture, 0, 0, 
				mTexture.getTextureWidth(), mTexture.getTextureHeight());
	}

	public void initPosition(BlockPoint p)
	{
		mPosition = p;
	}
	
	public BlockPoint getPosition()
	{
		return mPosition;
	}
	
	public void setHasCollected()
	{
		mHasCollected = true;
	}
	
	public boolean hasCollected()
	{
		return mHasCollected;
	}
	
	public void render(float depth)
	{
		Vector pos = mScene.convertGRDToSCR(mPosition.x, mPosition.y, mPosition.z);

		GLES11.glMatrixMode(GLES11.GL_MODELVIEW_MATRIX);
		GLES11.glPushMatrix();
		
		float scale = mScene.getPlayer().getScale();
		pos.y = pos.y + mScene.getBlockWidth() / 2 * mScene.getPitch() * 0.6f - 
				(3 * scale);
		GLES11.glTranslatef(pos.x, pos.y, depth);	

		GLES11.glScalef(scale, scale, 1.0f);
		GLES11.glTranslatef(-COIN_SIZE / 2, -COIN_SIZE, 0.0f);
		
		mQuad.render(0, 0, mTexture.getTextureWidth(), mTexture.getTextureHeight());
		
		GLES11.glPopMatrix();		
		
	}
	
	public boolean isInBock(int x, int y, int z)
	{
		return x == mPosition.x && y == mPosition.y && z == mPosition.z;
	}
}
